package com.ghosthigh.simpleaccount.server.url;

public class Urls {

  static String ROOT = "/";
  static String STATIC_ROOT = "/s";
  static String STATIC_PATTERN = "/s/*";

  public String getRoot() {
    return ROOT;
  }

  public String getStaticRoot() {
    return STATIC_ROOT;
  }

  public String getStaticPattern() {
    return STATIC_PATTERN;
  }

  public String extractStaticHtmlFromPath(String requestURI) {
    if (requestURI.isEmpty() || requestURI.equals(ROOT) || requestURI.equals(STATIC_ROOT)) {
      return "/html/index.html";
    }
    assert requestURI.startsWith(STATIC_ROOT) : "STATIC PATH does not start with /s/";

    String remainPath = requestURI.substring(STATIC_ROOT.length()).replaceAll("/?$", "");

    if (remainPath.isEmpty()) {
      return "/html/index.html";
    }

    return "/html" + remainPath + ".html";
  }
}
